package com.snu.liwei.lyl_api.controller;

import com.snu.liwei.lyl_api.config.StaticConfig;
import com.snu.liwei.lyl_api.entity.User;
import com.snu.liwei.lyl_api.service.UserService;
import com.snu.liwei.lyl_api.tools.UMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@RestController
//this annotation can allow a special client server to cross domain which is banned by all browsers.
@CrossOrigin(origins = {"http://192.168.31.215:3000","http://127.0.0.1:3000"})
@RequestMapping(value = "User",produces = "application/json;charset=UTF-8")
public class RegisterController {

    @Autowired
    UserService userService;
    @RequestMapping("Register")
    public UMsg register(@RequestBody User registerUser) {
        System.out.println("注册接口");
        if(userService.getUser(registerUser)!=null){
            System.out.println("用户已存在，注册失败:"+registerUser.toString());
            return UMsg.failed();
        }
        userService.UserRegister(registerUser);
        User user=userService.getUser(registerUser);
        System.out.println(user);
        return UMsg.ok(user);
    }

    @RequestMapping("NotRegister")
    public String NotRegister()
    {
        System.out.println("未注册");
        return "Not Register";
    }
}
